Skip to contentSkip to conversation

Change in openvpn[master]: event: Silence conversion warning in tv_to_ms_timeout

Openvpn-devel In review flichtenheld (Code Review) 2 participants 7 messages Sep 11, 2025 – Sep 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1757601342000.Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email

to review the following change.

Change subject: event: Silence conversion warning in tv_to_ms_timeout
......................................................................

event: Silence conversion warning in tv_to_ms_timeout

The APIs want int (at least on unixy systems), so we use int. max_int() protects us against negative values.

Change-Id Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f

---
M src/openvpn/event.c

1 file changed, 10 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1178/1

src/openvpn/event.c +10 -9
index 2f60b78..ca84d19 100644
@@ -65,11 +65,15 @@
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Gerrit-Change-Number: 1178
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email )

Change subject: event: Silence conversion warning in tv_to_ms_timeout
......................................................................

Patch Set 7: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Gerrit-Change-Number: 1178
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 24 Sep 2025 13:49:26 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello MaxF, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email

to look at the new patch set (#8).

The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.

Change subject: event: Silence conversion warning in tv_to_ms_timeout
......................................................................

event: Silence conversion warning in tv_to_ms_timeout

The APIs want int (at least on unixy systems), so we use int. max_int() protects us against negative values.

Change-Id Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f

---
M src/openvpn/event.c

1 file changed, 10 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1178/8

src/openvpn/event.c +10 -9
index 2f60b78..ca84d19 100644
@@ -65,11 +65,15 @@
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Gerrit-Change-Number: 1178
Gerrit-PatchSet: 8
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#4 lore raw

PATCH v8 1/1 event: Silence conversion warning in tv_to_ms_timeout

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

The APIs want int (at least on unixy systems), so we use int. max_int() protects us against negative values.

Change-Id Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
This mail reflects revision 8 of this Change.

Acked-by according to Gerrit (reflected above):
MaxF <[email protected]...>

src/openvpn/event.c +10 -9
index 2f60b78..ca84d19 100644
@@ -65,11 +65,15 @@
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: event: Silence conversion warning in tv_to_ms_timeout

Trivial enough... and ACK from MaxF, so not testing anything beyond a quick local compile.

Your patch has been applied to the master branch.

commit da1d0064ae590213f0245125d6974850fecaa943

Author: Frank Lichtenheld
Date:   Wed Sep 24 16:57:09 2025 +0200
     event: Silence conversion warning in tv_to_ms_timeout

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: MaxF <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg33193.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#9) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by MaxF

Change subject: event: Silence conversion warning in tv_to_ms_timeout
......................................................................

event: Silence conversion warning in tv_to_ms_timeout

The APIs want int (at least on unixy systems), so we use int. max_int() protects us against negative values.

Change-Id Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33193.html

---
M src/openvpn/event.c

1 file changed, 10 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1178/9

src/openvpn/event.c +10 -9
index 2f60b78..ca84d19 100644
@@ -65,11 +65,15 @@
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Gerrit-Change-Number: 1178
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email )

Change subject: event: Silence conversion warning in tv_to_ms_timeout
......................................................................

event: Silence conversion warning in tv_to_ms_timeout

The APIs want int (at least on unixy systems), so we use int. max_int() protects us against negative values.

Change-Id Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33193.html

---
M src/openvpn/event.c

1 file changed, 10 insertions(+), 9 deletions(-)
src/openvpn/event.c +10 -9
index 2f60b78..ca84d19 100644
@@ -65,11 +65,15 @@
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1178?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Gerrit-Change-Number: 1178
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged